$(document).ready(function () {
	$("#loginimg").click(function () {
		$("#login").css("display", "none");
		$("#erm").css("display", "block");
	});

	$("#ermimg").click(function () {
		$("#login").css("display", "block");
		$("#erm").css("display", "none");
	});
});

//定义HTTP连接对象
var xmlHttp;

function login() {
	//实例化HTTP连接对象
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//发起登录请求
	var name = document.getElementById("user_id").value;
	var password = document.getElementById("user_pass").value;
	if (name == null || name == "") {
		innerHtml("请输入用户名");
		return;
	}
	if (password == null || password == "") {
		innerHtml("请输入密码");
		return;
	}
	var url = "user.php";
	xmlHttp.open("POST", url, true);
	xmlHttp.onreadystatechange = handleResult;
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send("action=login&name=" + name + "&psd=" + password);
}

//处理服务器返回的结果/更新页面
function handleResult() {
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		var response = xmlHttp.responseText;
		var json = eval("(" + response + ")");
		if (json["login_result"]) {
			alert("登录成功！");
			//window.location.href='MainTab/home.html';
		} else {
			innerHtml("用户名/密码错误");
		}
	} else if (xmlHttp.status != 200) {
		alert(xmlHttp.status);
	} else if (xmlHttp.readyState > 4 && xmlHttp.readyState == 0) {
		alert(xmlHttp.readyState);
	}
}

//插入提示语
function innerHtml(message) {
	document.getElementById("tip").innerHTML = "<span style='font-size:12px; color:red;'>" + message + "</span>";
}
